#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct TenantConfig {
  column: String,
  ignore_table: Vec<String>,
}
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct OSSConfig {
  key_id: String,
  key_secret: String,
  endpoint: String,
  bucket: String,
  access_endpoint: String,
}
impl OSSConfig {
  pub fn validate(&self) {
    if self.key_id.is_empty() || self.key_secret.is_empty() || self.endpoint.is_empty() || self.bucket.is_empty() {
      panic!("请配置oss ！！！！！！！！！！！！！！！！！！！")
    }
  }
}
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Default)]
pub enum UploadType {
  #[default]
  OSS,
}

#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct ServerConfig {
  host: String,
  port: Option<u16>,
  username: Option<String>,
  password: Option<String>,
}

#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct RedisConfig {
  host: String,
  port: Option<u16>,
  db: Option<i64>,
  username: Option<String>,
  password: Option<String>,
}

#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct MongodbConfig {
  host: String,
  port: Option<u16>,
}
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct DbConfig {
  r#type: Option<String>,
  host: String,
  port: Option<u16>,
  db: String,
  username: String,
  password: String,
}

#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct LogConfig {
  log_dir: String,
  log_temp_size: String,
  log_pack_compress: String,
  log_rolling_type: String,
  log_level: String,
}

///服务启动配置
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, Clone, Getters, Setters, MutGetters, Default)]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct ApplicationConfig {
  debug: bool,
  is_demo: bool,
  jwt_secret: String,
  ///redis url
  redis: RedisConfig,
  //mongodb url
  mongodb: MongodbConfig,
  /// db url default mysql
  database: DbConfig,
  ///default path "target/logs/"
  log: LogConfig,

  tenant: Option<TenantConfig>,
  oss: Option<OSSConfig>,
  server: ServerConfig,
}

impl ApplicationConfig {
  pub fn from_toml(toml_data: &str) -> Self {
    let config = match toml::from_str(toml_data) {
      Ok(e) => e,
      Err(e) => panic!("{}", e),
    };
    config
  }
}
